package com.qianduo.front.util;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Map.Entry;

import com.qianduo.front.model.City;
import com.qianduo.front.model.DaikuanCondition;

public class Common {
	public static String m2(double d,int length) {
		String lengthStr	= "";
		if(length > 0){
			lengthStr		+= ".";
			for(int i=0;i<length;i++){
				lengthStr	+= "0";
			}
		}
		DecimalFormat df = new DecimalFormat("#"+lengthStr);
		return df.format(d);
	}
	public static City getCityName(String cityID){
		City city	= null;
		if(null == cityID){ return city;}
		for(Entry<String,List<City>> entry : Global.citiesMap.entrySet()){
			List<City> list	= entry.getValue();
			if(null != list && list.size() > 0){
				for(City tmpCity : list){
					String tmpID	= tmpCity.getId();
					if(cityID.equals(tmpID)){
						city	= tmpCity;
						break;
					}
				}
			}
		}
		return city;
	}
	
	public static DaikuanCondition getConditionName(String conditionID){
		DaikuanCondition dc	= null;
		if(null == conditionID){ return dc;}
		for(Entry<String,List<DaikuanCondition>> entry : Global.mapConditions.entrySet()){
			List<DaikuanCondition> list	= entry.getValue();
			if(null != list && list.size() > 0){
				for(DaikuanCondition tmpDC : list){
					String tmpID	= tmpDC.getId();
					if(conditionID.equals(tmpID)){
						dc	= tmpDC;
						break;
					}
				}
			}
		}
		return dc;
	}
	
}
